package com.lenin.omena.client.event;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.lenin.omena.shared.LoginResult;

public class LoginEvent extends GwtEvent<LoginEventHandler> {

	public static Type<LoginEventHandler> TYPE = new Type<LoginEventHandler>();

	public static HandlerRegistration register(final EventBus eventBus,
			final LoginEventHandler handler) {

		return eventBus.addHandler(LoginEvent.TYPE, handler);

	}

	public enum ActionType {
		LOGIN, LOGOUT
	}
	
	private ActionType actionType;
	
	private LoginResult result;

	public LoginEvent(LoginResult result, ActionType actionType) {
		this.result = result;
		this.actionType = actionType;
	}

	public LoginResult getResult() {
		return result;
	}

	public ActionType getActionType() {
		return actionType;
	}
	
	@Override
	public Type<LoginEventHandler> getAssociatedType() {
		return LoginEvent.TYPE;
	}

	@Override
	protected void dispatch(final LoginEventHandler handler) {
		handler.onLogin(this);
	}

}